package com.hbpu.encap.homework;

public class Homework08 {
    public static void main(String[] args) {
        PersonA[] personAS = new PersonA[4];
        personAS[0] = new Student("小明", '男', 15, "00023102");
        personAS[1] = new Student("小王", '男', 22, "00023503");
        personAS[2] = new TeacherB("张飞", '男', 20, 5);
        personAS[3] = new TeacherB("吕布", '男', 32, 10);
        PersonA[] temp = new PersonA[1];
        for (int i = 0; i < personAS.length - 1; i++) {
            for (int j = 0; j < personAS.length - 1 - i; j++) {
                if (personAS[j].getAge() < personAS[j + 1].getAge()) {
                    temp[0] = personAS[j + 1];
                    personAS[j + 1] = personAS[j];
                    personAS[j] = temp[0];
                }
            }
        }
        for (int i = 0; i < personAS.length; i++) {
            System.out.println(personAS[i].toString());
        }
    }
}

class Student extends PersonA {
    private String stu_id;

    public Student(String name, char sex, int age, String stu_id) {
        super(name, sex, age);
        this.stu_id = stu_id;
    }

    @Override
    public String play(String name) {
        return super.play(name) + "爱玩足球！";
    }

    public void study() {
        System.out.println("我承诺，我会好好学习！");
    }

    public String getStu_id() {
        return stu_id;
    }

    public void setStu_id(String stu_id) {
        this.stu_id = stu_id;
    }

    @Override
    public String toString() {
        return "学生的信息：" + super.toString() + ", stu_id=" + stu_id;
    }
}

class TeacherB extends PersonA {
    private int work_age;

    public TeacherB(String name, char sex, int age, int work_age) {
        super(name, sex, age);
        this.work_age = work_age;
    }

    @Override
    public String play(String name) {
        return super.play(name) + "爱玩象棋！";
    }

    public void teach() {
        System.out.println("我承诺，我会认真教课！");
    }

    public int getWork_age() {
        return work_age;
    }

    public void setWork_age(int work_age) {
        this.work_age = work_age;
    }

    @Override
    public String toString() {
        return "老师的信息：" + super.toString() + ", work_age" + work_age;
    }
}

class PersonA {
    private String name;
    private char sex;
    private int age;

    public PersonA(String name, char sex, int age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
    }

    public String play(String name) {
        return name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "name='" + name + '\'' +
                ", sex=" + sex +
                ", age=" + age;
    }

    public void test(PersonA personA) {
        if (personA instanceof Student) {
            ((Student) personA).study();
        } else if (personA instanceof TeacherB) {
            ((TeacherB) personA).teach();
        } else {
            System.out.println("无");
        }
    }
}